<?php
try {
	if(file_exists("./core/core/view_interfaces/view_interfaces_loader.php")){
		require_once("./core/core/view_interfaces/view_interfaces_loader.php");
	}
	else {
		throw new Exception('Nie można załadować pliku: ./core/core/view_interfaces/view_interfaces_loader.php');
	}
}
catch(Exception $e){
	return $e->getMessage();
}
class Core_Core_Extraview implements Assignable, Renderable{
	
	private $data = array();
	private $render = FALSE;
	
	public function __construct($template){
		$file = SITE_ROOT . '/' . basename('views') . '/' . basename(strtolower($template)). '/' . basename(strotolower($template_file).'.php');
		try {
			if(file_exists($file)){
				$this->render = $file;
			}
			else {
				throw new Exception('Plik z szablonem nie mógł zostać wczytany: '.$file);
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
	}
	
	public function assign($variable, $value){
		
		$this->data[$variable] = $value;
		
	}
	
	public function render($direct_output = TRUE){
		
		try {
			
			if($direct_output !== TRUE){
				ob_start();
			}
			
			$data = $this->data;
			
			if(file_exists($this->render)){
				include($this->render);
			}
			else {
				throw new Exception('Plik z szablonem nie mógł zostać wczytany: '.$this->render);
			}
			
			if($direct_output !== TRUE){
				return ob_get_clean();
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
	}
	
	public function __destruct(){
		
	}
	
}